package es.index.logs.parse.squid;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Date;

import es.index.document.logs.squid.SquidStoreLog;
import es.index.logs.parse.LogsBaseParse;

public class SquidStoreLogsParse extends LogsBaseParse {
	
	public SquidStoreLogsParse() {
		super();
		String keys = "set_date,set_action,set_catalogNO,set_fileNO,set_cacheKeyword,"
				+ "set_statusCode,set_dateOf, set_lastDate, set_expirationDate,"
				+ "set_contentType,set_contentLength,set_contentSize,set_way,set_uri";
		_keys = keys.split(",");
	}

	@Override
	protected void setObjectLongValue(Method method, Object object, String value)
			throws NumberFormatException, IllegalAccessException,
			IllegalArgumentException, InvocationTargetException {
		if (method.getName().equals("set_fileNO"))
			method.invoke(object, Long.parseLong(value, 16));
		else
			method.invoke(object, Long.parseLong(value));
	}

	@Override
	protected void setObjectIntValue(Method method, Object object, String value)
			throws IllegalAccessException, IllegalArgumentException,
			InvocationTargetException {
		if (method.getName().equals("set_contentLength")) {
			String[] values = value.split("/");
			method.invoke(object, Integer.parseInt(values[0]));
			_line = values[1] + ' ' + _line;
		} else {
			method.invoke(object, Integer.parseInt(value));
		}
	}

	@Override
	protected Date getDate() {
		return getNumDate();
	}

	@Override
	protected Object getLogs() {
		SquidStoreLog log = new SquidStoreLog();
		log.set_id(ID());
		log.set_fileName(_fileName);
		setClassValue(log, 0, null, null);
		return log;
	}

	/**
	 * 初始化解析参数
	 */
	protected void initParseParamete() {
		initParseParamete(SquidStoreLog.class);
	}
}
